<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="performReservation.SMMDBBean"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Vector"%>
<%!
	String name = null;
	String actor = null;
	String category = null;
	String cinema = null;
	Vector<String[]> vec = new Vector<String[]>();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Search Result:</title>
</head>
<body>
	<center>Search Result</center>
	<%
		name = request.getParameter("name");
		actor = request.getParameter("actor");
		category = request.getParameter("category");
		cinema = request.getParameter("cinema");
		if(cinema.equals("")&&actor.equals("")&&category.equals("")&&name.equals("")){
			out.println("you need input a search condition at first!");
		}else if(actor.equals("")){
			SMMDBBean sProcess = SMMDBBean.getInstance();
			vec = sProcess.searchPWithoutActor(name,category,cinema);
			if(vec!=null){
			%>
			<TABLE border ="3" align="center">
	
			<TR>
				<TH>Name</TH>
				<TH>Cinema</TH>
				<TH>Actor</TH>
				<TH>Director</TH>
				<TH>Time</TH>
				<TH>Language</TH>
				<TH>Category</TH>
			</TR>
			
			<%
				for(int i = 0 ; i < vec.size();i++){
					String[] result = new String[9];
					result = vec.get(i);
					Vector<String[]> actors = new Vector<String[]>();
					actors = sProcess.getPerformanceActors(Integer.parseInt(result[0]));
					String actor = "";
					for(int j =0 ; j<actors.size();j++){
						String[] ac = new String[1];
						ac = actors.get(j);
						actor += ac[0];
					}
					if(actor.equals("")){
						actor="none";
					}
					%>
					<TR>
						<TD><a href="performDetail.jsp?num=<%=result[0] %>"><%=result[1] %></a></TD>
						<TD><a href=cinemaDetail.jsp?num=<%=result[2] %>"><%=result[3] %></a></TD>
						<TD><%=actor %></TD>
						<TD><%=result[5] %></TD>
						<TD><%=result[6] %></TD>
						<TD><%=result[7] %></TD>
						<TD><%=result[8] %></TD>
					</TR>
					<%
				}
			%></TABLE><%
			}else{
				out.println("sorry, no conform result");
			}
		
		}else{
			SMMDBBean sProcess = SMMDBBean.getInstance();
			vec = sProcess.searchP(name,actor,category,cinema);
			if(vec!=null){
			%>
			<TABLE border ="3" align="center">
	
			<TR>
				<TH>Name</TH>
				<TH>Cinema</TH>
				<TH>Actor</TH>
				<TH>Director</TH>
				<TH>Release Date</TH>
				<TH>Language</TH>
				<TH>Category</TH>
			</TR>
			
			<%
				for(int i = 0 ; i < vec.size();i++){
					String[] result = new String[11];
					result = vec.get(i);
					%>
					<TR>
						<TD><a href="performDetail.jsp?num=<%=result[0] %>"><%=result[1] %></a></TD>
						<TD><a href=cinemaDetail.jsp?num=<%=result[2] %>"><%=result[3] %></a></TD>
						<TD><%=result[6] %></TD>
						<TD><%=result[7] %></TD>
						<TD><%=result[8] %></TD>
						<TD><%=result[9] %></TD>
						<TD><%=result[10] %></TD>
					</TR>
					<%
				}
			%></TABLE><%
			}else{
				out.println("sorry, no conform result");
			}
		}
	%>
</body>
</html>